<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						
						<div class="layui-form-item layui-inline">
							<select name="year">
								<option value="">选择年份</option>
								{for start="$old_year" end="date('Y')+1"}
									{if $year == $i}
									<option value="{$i}" selected="selected">{$i}年</option>
									{else/}
									<option value="{$i}">{$i}年</option>
									{/if}
								{/for}
							</select>
						</div>
						
						<div class="layui-form-item layui-inline">
							<select name="month">
								<option value="">选择月份</option>
								{for start="1" end="13"}
									{if $month == $i}
									<option value="{$i}" selected="selected">{$i}月</option>
									{else/}
									<option value="{$i}">{$i}月</option>
									{/if}
								{/for}
							</select>
						</div>
						
						<div class="layui-form-item layui-inline">
							<select name="day">
								<option value="">选择天数</option>
								{for start="1" end="32"}
									{if $month == $i}
									<option value="{$i}" selected="selected">{$i}日</option>
									{else/}
									<option value="{$i}">{$i}日</option>
									{/if}
								{/for}
							</select>
						</div>
						
						<div class="layui-form-item layui-inline">
							<select name="sg">
								<option value="-1" {if $sg===-1} selected="selected" {/if}>不限</option>
								<option value="1" {if $sg===1} selected="selected" {/if}>手动录入</option>
								<option value="0" {if $sg===0} selected="selected" {/if}>系统生成</option>
							</select>
						</div>
						<label>共查询到 <span id="count"></span> 条记录,合计金额： <span id="total"></span> 元</label>
					</div>
					<div class="layui-form-item">
							
						<div class="layui-form-item layui-inline">
							<input name="type" type="radio" value="-1" title="所有" {if $type===-1} checked {/if}>
							<input name="type" type="radio" value="0" title="支出" {if $type===0} checked {/if}>
							<input name="type" type="radio" value="1" title="收入" {if $type===1} checked {/if}>
						</div>
					
					   <div class="layui-form-item layui-inline">
						   <div class="layui-input-inline2 input-group">
							   <span class="input-group-addon">项目</span>
							   <input type="text" name="name" placeholder="项目 / 备注" class="layui-input">
						   </div>
					   </div>
                        <div class="layui-form-item layui-inline">
                       <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                           <i class="layui-icon layui-icon-search"></i>
                           查询
                       </button>
                       <button type="reset" class="pear-btn pear-btn-md">
                           <i class="layui-icon layui-icon-refresh"></i>
                           重置
                       </button>
					   <button id="today" type="button" class="pear-btn pear-btn-md pear-btn-primary">
					       <i class="layui-icon layui-icon-search"></i>
					       查今天
					   </button>
                       </div>
                    </div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="dataTable" lay-filter="dataTable"></table>
			</div>
		</div>

		<script type="text/html" id="toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="pop" url="{:U('bill.main/add',['type'=>0])}" poptitle="添加支出">
		        <i class="layui-icon layui-icon-add-1"></i>
		        支出
			</button>
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="pop" url="{:U('bill.main/add',['type'=>1])}" poptitle="添加收入">
			    <i class="layui-icon layui-icon-add-1"></i>
			    收入
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
		</script>

        
		<script type="text/html" id="typetpl">
			{{# if(d.type==0){ }}
				<span class="layui-tag pear-btn-red">支出</span>
			{{# }else{ }}
				{{# if(d.money==0){ }}
				<span class="layui-tag pear-btn-grey">收入</span>
				{{# }else{ }}
				<span class="layui-tag pear-btn-green">收入</span>
				{{# } }}
			{{# } }}
		</script>
		
		<script type="text/html" id="moneytpl">
			{{# if(d.money==0){ }}
				<span style="color:#269E26;">{{d.money}} 元</span>
			{{# }else if(d.money<0){ }}
				<span style="color:#D63333;">{{d.money}} 元</span>
			{{# }else{ }}
				<span style="color:#269E26;">{{d.money}} 元</span>
			{{# } }}
		</script>
		
		<script type="text/html" id="addtypetpl">
			{{# if(d.addtype==0){ }}
				<span>系统生成</span>
			{{# }else{ }}
				<span class="layui-tag pear-btn-grey">手动录入</span>
			{{# } }}
		</script>
		
		<script type="text/html" id="remarktpl">
			{{# if(d.did>0){ }}
				<a href="javascript:;" popDealInfo="{:U('deal.main/printing')}/id/{{d.did}}/number/{{d.deal_number}}" title="【{{d.deal_number}}】 订单明细">{{d.remark}}</a>
			{{# }else{ }}
				{{d.remark}}
			{{# } }}
		</script>
		
		<script type="text/html" id="status">
		   <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" {{# if(d.status==1){ }} checked {{# } }}>
		</script>

		<script type="text/html" id="options">
		<div class="layui-options">
			{{# if(d.addtype==1){ }}
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
			{{# } }}
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</div>
		</script>
        <script>
        layui.use(['jquery','common','mycomm','table'], function() {
            let $ = layui.jquery;
			let common = layui.common;
			let table = layui.table;
			let mycomm = layui.mycomm;
            let MODULE_PATH = "{$MODULE_PATH}";
            let $table_name = "dataTable";
            
            let cols = [
                [{
                        type: 'checkbox'
					}, {
                       field: "create_time",
                       title: "日期时间",
					   width: 120,
                       unresize: "true",
                       align: "center",
                   }, {
                       field: "type",
                       title: "收支类型",
					   width: 100,
					   templet: "#typetpl",
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "name",
                       title: "收支项目",
					   width: 120,
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "money",
                       title: "收支金额",
					   width: 120,
					   templet: "#moneytpl",
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "remark",
                       title: "收支备注",
					   templet: "#remarktpl",
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "addtype_text",
                       title: "生成方式",
					   width: 140,
					   templet: "#addtypetpl",
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "status",
                       title: "收支状态",
					   width: 120,
                       unresize: "true",
                       align: "center",
                       templet:"#status",
                   }, {
                        title: '操作',
                        toolbar: '#options',
                        unresize: true,
                        align: 'left',
                        width:160,
                    }
                ]
            ]
			
			table.render({
				elem: '#dataTable',
				url: MODULE_PATH + 'index',
				where:{year:{$year},month:{$month},day:{$day},type:'{$type}',sg:{$sg}},
				page: true,
				cols: cols,
				cellMinWidth: 100,
				even: true,
				limit: 20,
				toolbar: '#toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports'],
				done: function(res, curr, count){
					$('#total').html(res.total);
					$('#count').html(res.count);
				}
			});
			
			mycomm.tableTool('{$controller_title}',MODULE_PATH,$table_name);
			mycomm.tableToolBar('{$controller_title}',MODULE_PATH,$table_name);
			mycomm.search_table($table_name);
			mycomm.tableSetVal(MODULE_PATH);
			mycomm.formSwitch('status',MODULE_PATH);
			
			
			$("#today").click(function(){
				var year = "dd[lay-value='{:date('Y')}']";
				var month = "dd[lay-value='{:date('m')}']";
				var day = "dd[lay-value='{:intval(date('d'))}']";
				$('[name="year"]').siblings("div.layui-form-select").find('dl').find(year).click();
				$('[name="month"]').siblings("div.layui-form-select").find('dl').find(month).click();
				$('[name="day"]').siblings("div.layui-form-select").find('dl').find(day).click();
				$("[lay-submit]").click();
			});

			$('body').on('click', '[popDealInfo]',function(){
			    var title=$(this).attr('title');
				var url=$(this).attr('popDealInfo');
				mycomm.tool_pop(url,title,0.9);
			})
        })
    </script>
	{$LOAD_STYLE.bottom|raw}
	</body>
</html>
